# Makefile for DCU vs CUDA Performance Evaluation

# Compiler and flags
NVCC = nvcc
HIPCC = hipcc
CXX_FLAGS = -O3 -std=c++11
NVCC_FLAGS = $(CXX_FLAGS)
HIPCC_FLAGS = $(CXX_FLAGS) --offload-arch=gfx906

# Directories
SRC_DIR = src
BIN_DIR = bin
CUDA_SRC = $(SRC_DIR)/cuda/main.cu
HIP_SRC = $(SRC_DIR)/hip/main.cpp

# Targets
CUDA_TARGET = $(BIN_DIR)/cuda_performance
HIP_TARGET = $(BIN_DIR)/hip_performance

# Default target
all: cuda hip

# Build rules
$(CUDA_TARGET): $(CUDA_SRC)
	@mkdir -p $(BIN_DIR)
	$(NVCC) $(NVCC_FLAGS) -o $@ $<

$(HIP_TARGET): $(HIP_SRC)
	@mkdir -p $(BIN_DIR)
	$(HIPCC) $(HIPCC_FLAGS) -o $@ $<

# Platform-specific targets
cuda: $(CUDA_TARGET)
hip: $(HIP_TARGET)

# Run tests
run-tests: all
	@echo "Running all tests..."
	@bash scripts/run_tests.sh

run-cuda-tests: cuda
	@echo "Running CUDA tests..."
	@bash scripts/run_tests.sh --platform cuda

run-hip-tests: hip
	@echo "Running HIP tests..."
	@bash scripts/run_tests.sh --platform hip

# Analysis
analyze:
	@echo "Analyzing results..."
	@python3 scripts/analyze.py

# Clean build artifacts
clean:
	@echo "Cleaning build artifacts..."
	@rm -rf $(BIN_DIR) output

# Help
help:
	@echo "Usage: make [target]"
	@echo ""
	@echo "Available targets:"
	@echo "  all              - Build both CUDA and HIP test programs (default)"
	@echo "  cuda             - Build the CUDA test program"
	@echo "  hip              - Build the HIP test program"
	@echo "  run-tests        - Run the full test suite for both platforms"
	@echo "  run-cuda-tests   - Run the test suite for CUDA only"
	@echo "  run-hip-tests    - Run the test suite for HIP only"
	@echo "  analyze          - Run the Python analysis script on the test results"
	@echo "  clean            - Remove all built programs and output logs"
	@echo "  help             - Show this help message"

.PHONY: all cuda hip run-tests run-cuda-tests run-hip-tests analyze clean help